<template>
	<!-- 抵扣设置 -->
	<view class="e_wp">
		<view class="e_li flex_end saoyx">
			<view @click="saoyx()">扫一扫</view>
			<uni-icons type="scan" size="20" color="#666" @click="saoyx()"></uni-icons>
		</view>
		<view class="e_li">
			<text>设备类型：</text>
			<view class="e_li_radio">
				<label @click="typeTap(1)">
					<radio color="#8405dc" :checked="type==1"></radio>云音响
				</label>
				<label @click="typeTap(3)">
					<radio color="#8405dc" :checked="type==3"></radio>云音响+云打印
				</label>
			</view>
		</view>
		<view class="e_li" style="padding-bottom:30rpx;">
			<text>设备号：</text>
			<input type="text" disabled="" placeholder="请扫描二维码" v-model="imei" />
			<uni-icons v-show="imei!=''" type="clear" size="20" color="#999" @click="clearImei()"></uni-icons>
		</view>

		<button class="totalBtn" @click="sumbit">提交</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				uid:'',
				type: 1,
				imei: '',
			}
		},
		onLoad(options) {
			this.uid=options.uid;
			this.getInfo();
		},
		methods: {
			saoyx(){
				var that = this;
				uni.showLoading({
					title: '识别中',
					mask: true
				});
				uni.scanCode({
					success: function(res) {
						uni.hideLoading();
						console.log(res)
						that.imei = res.result.split('|')[0];
					},
					fail(error) {
						uni.hideLoading();
						that.$api.msg('扫码失败')
					}
				})
			},
			clearImei(){
				this.imei = '';
			},
			sumbit() {
				if (this.imei === '') {
					this.$api.msg('请填写完善信息！');
					return
				}
				this.$axios('info/setDevice', 'POST', 'supplier', {
					type: this.type,
					imei: this.imei,
					uid:this.uid
				}).then(res => {
					if (res.data.code == 200) {
						this.$api.msg('提交成功');
						setTimeout(() => {
							this.$navRed('../business/personalstores?uid='+this.uid);
						}, 1000)
					}
				})
			},
			getInfo() {
				this.$axios('info/getDevice', 'POST', 'supplier',{
					uid:this.uid
				}).then(res => {
					if (res.data.code == 200) {
						let data = res.data.data;
						if (data) {
							this.type = data.type;
							this.imei = data.imei;
						}
					}
				})
			},
			typeTap(v) {
				if (v == this.type) return;
				this.type = v;
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f2f2f2;
		color: $font-color-dark;
	}
	.saoyx{
		font-size: 32rpx;
		view{
			margin-right: 10rpx;
			margin-top: -8rpx;
		}
	}
	.e_li {
		background-color: #FFFFFF;
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		padding: 0 20rpx;
		padding-top: 30rpx;
	}

	.e_old {
		padding-top: 30upx;
	}

	.e_li_radio {
		display: flex;
		align-items: center;
	}

	.e_li_radio label {
		margin-right: 20upx;
	}

	.e_li_radio radio {
		transform: scale(0.7);
	}
</style>
